<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>手机官网管理</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <%@include file="../include/commonFile.jsp" %>
    <style type="text/css">
        .copy-btn {
            position: absolute;
            top: 0;
            right: -100px;
        }
    </style>
</head>
<body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <form class="layui-form" action="${ctx}/subject/subject/subjectList.do" id="myForm" method="post">
                <input type="hidden" name="pageNo" id="pageNo"/>
                <div class="f-search-bar">
                    <div class="search-container">
                        <ul class="search-form-content">
                            <li class="form-item-inline"><label class="search-form-lable">手机官网名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="name" autocomplete="off" class="layui-input"
                                           value="${subject.name}" placeholder="请输入查询手机官网名称">
                                </div>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable">发布者</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="memberName" autocomplete="off" class="layui-input"
                                           value="${input.memberName}" placeholder="请输入查询手机官网发布者">
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <div class="sub-btns">
                                    <a class="layui-btn layui-btn-danger"
                                       href="javascript:submitFunction('#myForm')">查询</a>
                                    <a class="layui-btn layui-btn-normal"
                                       href="javascript:resetFunction('#myForm')">重置</a>
                                </div>
                            </li>
                        </ul>
                        <ul class="search-form-content">
                            <li class="form-item"><label class="search-form-lable">发布时间</label>
                                <div class="check-btn-inner" id="timeType">
                                    <a id="all" href="javascript:void(0);"
                                       onclick="setTimeType($(this),0,'#myForm')" ${empty input.timeType || input.timeType == 0 ? 'class="active"' : ''}>全部</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),1,'#myForm')" ${input.timeType == 1 ? 'class="active"' : ''}>今天</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),2,'#myForm')" ${input.timeType == 2 ? 'class="active"' : ''}>本周内</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),3,'#myForm')" ${input.timeType == 3 ? 'class="active"' : ''}>本月内</a>
                                    <input type="hidden" name="timeType" value="${input.timeType}"/>
                                </div>
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createStart"
                                               value="${input.createStart}" placeholder="开始日">
                                    </div>
                                    -
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createEnd"
                                               value="${input.createEnd}" placeholder="截止日">
                                    </div>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </form>
            <div class="c-time-list-content">
                <ul>
                    <c:if test="${page.totalCount == 0}">
                        <div class="f16 tc mt15">还没有数据，请点击右上角的“发布手机官网”，发布和编辑内容</div>
                    </c:if>
                    <c:forEach var="subject" items="${subjects}">
                        <li>
                            <div class="detail-content">
                                <a href="${ctx}/subject/subject/subjectDetail.do?id=${subject.id }"
                                   class="act-logo common-img"
                                >
                                    <img src="<c:if test="${ subject.picture!= null}">${subject.picture}?imageMogr2/auto-orient/crop/200x150</c:if>"
                                         alt="" onerror="txz.errImg(this)" onload="txz.imgLoad(this)">
                                </a>
                                <div class="detail">
                                    <div class="act-title">
                                        <a title="${subject.name }"
                                           href="${ctx}/subject/subject/subjectDetail.do?id=${subject.id }"
                                           class="title f18 ell db">${subject.name }</a>
                                    </div>
                                    <div class="">
                                        <p class="act-price">
											<span style="margin-right: 20px;"> 栏目数量：<b class='active-red'>${fn:length(subject.subjectApplies)}</b></span>
                                            <span>发布者：<b class="active-red">${subject.memberName}</b></span>
                                        </p>
                                        <p class="start-time ell" title="${subject.remarks }">描述：${subject.remarks }</p>
                                        <p class="act-price">
                                            发布时间：
                                            <fmt:formatDate value="${subject.updateDate}" pattern="yyyy-MM-dd HH:mm"/>
                                        </p>
                                    </div>
                                    <div class="opts-btns tb-opts" style="width:475px">
                                        <div class="comm-opts">
                                            <a class="qr-btn" href="javascript:txz.openQrDialog({
												title:'扫码二维码可预览分享',
												detailList:[{
													title:'手机官网详情二维码',
													url:'${subject.qrCodeUrl}'
												}]
											})"><i class="iconfont icon-qrcode btn-icon"></i> 二维码</a>
                                            <a href="${ctx}/subject/subject/subjectForm.do?id=${subject.id }">
                                                <i class="iconfont icon-edit btn-icon"></i> 编辑</a>
                                            <a href="javascript:copyDialog('${subject.id }')">
                                                <i class="iconfont icon-copy btn-icon"></i> 复制手机官网</a>
                                            <a href="javascript:txz.deleteObject('确定要删除吗？','${ctx}/subject/subject/delete.do?id=${subject.id}','该手机官网下已有栏目，不能删除')">
                                                <i class="iconfont icon-delete btn-icon"></i> 删除
                                            </a>
                                            <a href="${ctx}/subject/apply/applyList.do?subjectId=${subject.id }">
                                                <i class="iconfont icon-peoplelist btn-icon"></i>
                                                栏目管理
                                            </a>
                                            <a href="javascript:checkQrCode('${subject.id}');">检查二维码</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </li>
                    </c:forEach>
                </ul>
            </div>
            <div id="page_content" class="page-container"></div>
        </div>
        <%@include file="../include/footer.jsp" %>
    </section>
    <%-- 复制手机官网 --%>
    <div id="copy_merchant" style="display: none;">
        <h3 class="tc mt20 mb10 f16">确认复制手机官网所有内容？</h3>
        <form class="layui-form pt20 pb20" method="post" action="">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">复制到机构</label>
                    <div class="layui-input-inline">
                        <input id="copy_name" type="text" class="layui-input" readonly/>
                        <a href="javascript:void(0);" class="layui-btn layui-btn-normal copy-btn"
                           onclick="openSelMemberDialog(this,'选择机构','${ctx}/system/member/selectPartner.do','950px','570px');">复制机构</a>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript" src="${ctx}/script/common/table_option.js"></script>
<script type="text/javascript">

    var merchantId = null;
    var merchantName = null;

    $(function () {
        //加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            page: '${page.page}'
        });
        layui.use(['laydate'], function () {
            var laydate = layui.laydate;
            // 查询发布日期
            var start = {
                elem: 'input[name=createStart]'
            };

            var end = {
                elem: 'input[name=createEnd]'
            };
            laydate.render(start);
            laydate.render(end);
        });
    })

    function copyDialog(subjectId) {
        var index = layer.open({
            type: 1,
            area: '430px',
            title: '系统提示',
            content: $("#copy_merchant"),
            btn: ['确定', '取消'],
            success: function () {
                merchantId = null;
                merchantName = null;
            },
            end: function () {
                merchantId = null;
                merchantName = null;
            },
            yes: function () {
                var index = layer.load(1);
                $.post("${ctx}/subject/subject/copySubject.do", {
                    'subjectId': subjectId,
                    'memberId': merchantId
                }, function (ret) {
                    layer.close(index);
                    if (ret.success == true) {
                        util.layerMsgSuccess("成功", function () {
                            window.location.reload();
                        });
                    } else {
                        util.layerMsgError("失败")
                    }
                });
            }
        });
    }

    function checkQrCode(subjectId) {
        var confirmIndex = layer.confirm('确认要检查该手机官网的二维码是否存在?', {title: '系统提示'}, function (index) {
            layer.close(confirmIndex);
            //loading层
            var loadIndex = layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });
            $.post('${ctx}/subject/subject/checkQrCode.do', {
                subjectId: subjectId
            }, function (res) {
                layer.close(loadIndex);
                if (res.success == true) {
                    util.layerMsgSuccess("成功")
                } else {
                    util.layerMsgError("失败")
                }
            })
        });
    }

    function openSelMemberDialog(that, title, url, width, height) {
        txz.openDialogIframe({
            width: width,
            height: height,
            title: title,
            url: url,
            cb: function (opt) {
                var content = opt.content;
                if (content.doSubmit()) {
                    var data = content.returnData();
                    $("#copy_name").val(data.name);
                    merchantId = data.id;
                    merchantName = data.name;

                    top.layer.close(opt.index);
                }
            }
        })
    }
</script>
<script type="text/javascript">
    txz.initHeader({
        nav: [{
            name: '手机官网管理',
            curr: true
        }],
        info: '<span class="f12">共<b id="totalCount">${page.totalCount}</b>条记录</span>',
        btns: [{
            name: '发布手机官网',
            href: '${ctx}/subject/subject/subjectForm.do',
            icon: 'add'
        }]
    });
</script>
</body>
</html>